package com.wn.web;

import com.github.pagehelper.PageInfo;
import com.wn.common.pojo.PageParam;
import com.wn.common.pojo.Resteraunt;
import com.wn.common.pojo.Rsp;
import com.wn.service.FileServicePackage.FileService;
import com.wn.service.ResterauntService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@RestControllerAdvice
@RequestMapping("resteraunt")
@Api(value = "饭店接口",description="饭店接口")
public class ResterauntController {
    @Autowired
    private ResterauntService resterauntService;
    @Autowired
    private FileService fileService;

    /**
     * 查询所有
     * @param newsinfoPageParam 前端过来的必要的分页字段名
     * @return
     */
    @PostMapping("queryAll")
    public Rsp queryAll(@RequestBody PageParam<Resteraunt> newsinfoPageParam){
        PageInfo pageInfo = resterauntService.queryAll(newsinfoPageParam);
        return Rsp.success(pageInfo);
    }

    /**
     * 逻辑删除
     * @param resteraunt
     * @return
     */
    @PostMapping("deleteResteraunt")
    public Rsp deletelogic(@RequestBody Resteraunt resteraunt){
       return resterauntService.deletelogic(resteraunt);
    }

    /**
     * 根据用户id查找
     * @return
     */
    @PostMapping("selectById")
    public Rsp selectById(@RequestBody Resteraunt resteraunt){
        return resterauntService.selectById(resteraunt.getId());
    }

    /**
     * 增加数据
     * @param resteraunt
     * @param
     * @return
     */
    @PostMapping("add")
    public Rsp add(@RequestBody @Valid Resteraunt resteraunt){
//       resteraunt.setCreateUserId(userId);

       return resterauntService.add(resteraunt);
    }


    /**
     * 更新数据
     * @param resteraunt
     * @return
     */
    @PostMapping("updateResteraunt")
    public Rsp update(@RequestBody @Valid Resteraunt resteraunt){
        System.out.println(resteraunt.toString());
        return resterauntService.update(resteraunt);
    }


    //修改城市的状态
    @PostMapping("updateNewsinfo")
    public Rsp updateNewsinfo (@RequestBody Resteraunt resteraunt){
        Rsp rsp = resterauntService.updateNewsinfo(resteraunt);

        return rsp;
    }
}
